import { message, Modal } from "ant-design-vue";
import { ExclamationCircleOutlined } from "@ant-design/icons-vue";
import { createVNode, Ref } from "vue";
import { deleteFeeToPayableApi } from "@/api/financialManagement/payableManagement";
export default function OperationHook(state: {
  drawerOpts: Base.DrawerOpts;
  passData: Ref<Base.GeneraDataType>;
  dialogOpts: Base.DialogOpts;
  formState: StatementPayable.FeeInfo;
  emit: any;
  loading: Ref<boolean>;
  init: (id: string, selectNext?: boolean) => void;
}) {
  const { drawerOpts, dialogOpts, passData, init } = state;
  // 查看发票
  const showInvoiceHandle = () => {
    drawerOpts.width = "1200px";
    drawerOpts.title = "查看发票";
    drawerOpts.type = 1;
    drawerOpts.passData = { id: passData.value.waybillId };
    drawerOpts.component = "ShowInvoice";
    drawerOpts.visible = true;
  };
  const addFeeHandle = () => {
    dialogOpts.width = "520px";
    dialogOpts.title = "添加费用";
    dialogOpts.type = 1;
    dialogOpts.passData = {};
    dialogOpts.component = "AddFee";
    dialogOpts.visible = true;
  };
  const editFeeHandle = (row: Base.GeneraDataType) => {
    dialogOpts.width = "520px";
    dialogOpts.title = "编辑费用";
    dialogOpts.type = 2;
    dialogOpts.passData = row;
    dialogOpts.component = "AddFee";
    dialogOpts.visible = true;
  };
  const deleteFeeHandle = (row: Base.GeneraDataType) => {
    Modal.confirm({
      title: "是否删除当前费用?",
      icon: createVNode(ExclamationCircleOutlined),
      onOk() {
        deleteFeeToPayableApi(row.id).then((res: any) => {
          const { code } = res;
          if (code === 200) {
            message.success("删除成功!");
            init(passData.value.id);
          }
        });
      }
    });
  };
  return {
    showInvoiceHandle,
    addFeeHandle,
    editFeeHandle,
    deleteFeeHandle
  };
}
